package com.sheepone.util.number;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * @author Miss.杨
 * @description
 * @since 2024/1/30 - 17:14
 */
public class NumberStringConvertUtil {
    private static final DecimalFormat NUM_TO_RMB=new DecimalFormat("###,###.00");

    /**
     * ￥123,111.00
     * @param number
     * @return
     */
    public static String numberToRMBString(BigDecimal number){
        return "￥"+NUM_TO_RMB.format(roundToTwoDecimalPlaces(number));
    }

    /**
     * 四舍五入保留两位小数
     * @param number
     * @return
     */
    public static BigDecimal roundToTwoDecimalPlaces(BigDecimal number) {
        return number.setScale(2, RoundingMode.HALF_UP);
    }
}
